package com.lagou.email;

import org.apache.commons.lang.RandomStringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.concurrent.TimeUnit;

@SpringBootTest(classes = EmailApplication.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class EmailTst {


    @Autowired
    private JavaMailSender javaMailSender;

    @Test
    public void testSendMail(){

        String code = RandomStringUtils.randomNumeric(6);
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //发送方
        mailMessage.setFrom("youran9908@163.com");
        //接收方
        mailMessage.setTo("990813997@qq.com");
        //主题
        mailMessage.setSubject("注册验证码");
        //内容
        mailMessage.setText("您的注册验证码: "+code);


        javaMailSender.send(mailMessage);

        System.out.println(code);
    }


}
